package com.lsy.weizhi2.activity;

import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.ViewTreeObserver;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.adapter.MyGoldMasterAdapter;
import com.lsy.weizhi2.config.MyHeight;
import com.lsy.weizhi2.mybase.MyBaseActivity;
import com.lsy.weizhi2.mybase.MyTitleView;

public class MyGoldMaster extends MyBaseActivity {
    private Context context;
    private MyTitleView my_gold_master_title;
    private TextView my_gold_master_num;
    private RecyclerView my_gold_master_rv;
    private MyGoldMasterAdapter myGoldMasterAdapter;
    private int xx;
    private Handler handler=new Handler();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_gold_master);
        context=MyGoldMaster.this;
        Init();
    }

    private void Init() {
        my_gold_master_title= (MyTitleView) findViewById(R.id.my_gold_master_title);
        my_gold_master_num= (TextView) findViewById(R.id.my_gold_master_num);
        my_gold_master_rv= (RecyclerView) findViewById(R.id.my_gold_master_rv);
        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        my_gold_master_rv.setLayoutManager(manager);
        myGoldMasterAdapter=new MyGoldMasterAdapter(context,null);
        my_gold_master_rv.setAdapter(myGoldMasterAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        SpannableStringBuilder spannableStringBuilder=new SpannableStringBuilder("您共有8位土豪金主");
        spannableStringBuilder.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.price)),3,5,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        my_gold_master_num.setText(spannableStringBuilder);
        xx=0;
        new Thread(new Runnable() {
            @Override
            public void run() {
                ViewTreeObserver vto = my_gold_master_title.getViewTreeObserver();
                vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (xx < 1) {
                            xx++;
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(my_gold_master_title.getLayoutParams());
                                    params.height = MyHeight.ACTIONBAR + MyHeight.MyTitleHeight;
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                        my_gold_master_title.setLayoutParams(params);
                                    }
                                }
                            });
                        }
                    }
                });
            }
        }).start();
    }
}
